package com.common.web.dto.response;

import java.util.HashMap;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * ResponseBody
 * @author ficus
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class RestResponse extends HashMap<String, Object> {
	
	private static final long serialVersionUID = 1L;

	/** 返回状态码*/
	private String resultCode;
	/** 返回消息描述*/
	private String resultMsg;
	
	/**返回数据*/
	private Object data;
	
	public static RestResponse success(){
        return success("成功");
    }
	
	public static RestResponse unknowResult(){
		RestResponse result=new RestResponse();
		result.setResultCode("999");
		result.setResultMsg("未知错误");
		return result;
	}
	
	public static RestResponse noResourceResult(){
		RestResponse result=new RestResponse();
		result.setResultCode("404");
		result.setResultMsg("访问路径错误");
		return result;
	}
	
	
    public static RestResponse success(String message){
        RestResponse restResponse = new RestResponse();
        restResponse.setResultCode("200");
        restResponse.setResultMsg(message);
        return restResponse;
    }

    public static RestResponse failure(String message){
        RestResponse restResponse = new RestResponse();
        restResponse.setResultCode("500");
        restResponse.setResultMsg(message);
        return restResponse;
    }

    public RestResponse setData(Object data) {
    	this.data=data;
    	this.put("data", data);
        return this;
    }
    
    public RestResponse setResultCode(String resultCode) {
    	this.resultCode=resultCode;
    	this.put("resultCode", resultCode);
        return this;
    }
    
    public RestResponse setResultMsg(String resultMsg) {
    	this.resultMsg=resultMsg;
    	this.put("resultMsg", resultMsg);
        return this;
    }
    
    
    public RestResponse setAny(String key, Object value) {
        if (key != null && value != null) {
            put(key, value);
        }
        return this;
    }
    
}
